<template>
  <span>
    <span v-if="type === 'Text' || type === 'Date'">
      {{ scope }}
    </span>
    <el-button
      v-for="(item, index) in operate"
      v-show="permissionShowIn && permissionBoolean(item.text)"
      v-else
      :key="index"
      :type="item.color"
      size="mini"
      @click="onSubmit(scope,item.type)">{{ item.text }}</el-button>
  </span>
</template>

<script>
export default {
  name: 'Item',
  props: {
    type: {
      type: String,
      required: true
    },
    rowname: {
      type: String,
      required: true
    },
    scope: {
      type: [String, Number],
      require: true,
      default: ''
    },
    operate: {
      type: Array,
      default: function() {}
    },
    permissionDataIn: {
      type: Array,
      default: function() {}
    },
    permissionShowIn: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      itemType: 'Text'
    }
  },
  computed: {
    permissionBoolean() {
      return function(str) {
        const arr = []
        for (let i = 0; i < this.permissionDataIn.length; i++) {
          arr.push(this.permissionDataIn[i].name)
        }
        const index = arr.indexOf(str)
        // console.log(arr)
        // console.log('index', index, str)
        if (index !== -1) {
          return true
        } else {
          return false
        }
      }
    }
  },
  mounted() {
  },
  methods: {
    onSubmit(index, type) {
      this.$emit('submit', index, type)
    }
  }
}
</script>
<style>

</style>

